package cn.dengta.webapp.trade.dao;

import java.util.List;

import cn.dengta.common.web.Page;
import cn.dengta.webapp.base.dao.BaseDao;
import cn.dengta.webapp.user.entity.Relation;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 关注 Mapper 接口
 *
 * @author zw
 * @since 2023-01-30
 */
public interface UserRelationDao extends BaseDao<Relation> {

	/** 返回与指定用户存在拉黑关系的用户ID集合（主动拉黑对方 或 被对方拉黑 都算） */
	@Select("SELECT to_user_id FROM dt_relation WHERE user_id = #{userId} AND status < 0")
	List<Long> findAnyBlockUserIdsFor(@Param("userId") Long userId);

	@Select("SELECT COUNT(*) FROM dt_relation WHERE to_user_id = #{userId} AND status = 1")
	Long getFollowCount(@Param("userId") Long userId);

	/** 查询正在直播的好友用户ID */
	@Select("SELECT r.to_user_id FROM dt_relation r" +
			" JOIN im_live_anchor l ON r.user_id = #{userId} AND r.to_user_id = l.id AND r.status = 1 AND r.to_status = 1 AND l.live_status=1 AND !(l.config_flag & 1)" +
			" ORDER BY r.id")
	Page<Long> findLiveAnchorUserIdsFor(@Param("userId") Long userId, Page<?> page);

}
